#include "MetallFactory.h"
#include "..\Components\AnimationComponent.h"
#include "..\Components\PhysicsComponent.h"
#include "..\Components\SensorComponent.h"
#include "..\Components\VisualComponent.h"
#include "..\Components\MetallAIComponent.h"
#include "..\Components\DamageComponent.h"
#include "..\Components\HealthComponent.h"
#include "..\Components\CollisionComponent.h"
#include <functional>

MetallFactory::MetallFactory()
{
}


MetallFactory::~MetallFactory()
{
}

GameObject* MetallFactory::createEnemy(const vn::Vector2& p_position, const std::string& p_target)
{
	GameObject* go = new GameObject("metall", nullptr, nullptr);
	IComponent* visualComponent = new VisualComponent(1, "metal_enemy");
	go->addComponent(visualComponent);
	
	IComponent* animationComponent = new AnimationComponent("animations/metall.xml");
	go->addComponent(animationComponent);

	IComponent* physicsComponent = new PhysicsComponent(b2_dynamicBody, b2Vec2(25.0f, 15.0f), b2Vec2(p_position.x, p_position.y), FIXT_ID_ENEMY, COLLF_ENEMY, COLLF_WORLD);
	static_cast<PhysicsComponent*>(physicsComponent)->getBody()->SetFixedRotation(true);
	go->addComponent(physicsComponent);

	IComponent* sensorComponent = new SensorComponent(FIXT_ID_ENEMY_SENSOR, b2Vec2(25.0f, 15.0f), b2Vec2(0.0f, 0.0f), 0, COLLF_ENEMY_SENSOR, COLLF_PLAYER | COLLF_PLAYER_BULLET_SENSOR);
	go->addComponent(sensorComponent);
	
	IComponent* metallAIComponent = new MetallAIComponent("player");
	go->addComponent(metallAIComponent);

	IComponent* damageComponent = new DamageComponent(4);
	go->addComponent(damageComponent);

	IComponent* healthComponent = new HealthComponent(0, 8);
	std::function<void()> func = [=] { go->removeMe(); };
	static_cast<HealthComponent*>(healthComponent)->setDeathCallback(func);
	go->addComponent(healthComponent);

	go->initComponents();

	return go;
}